package {
 import flash.display.*;
 import flash.events.*;
 import away3d.objects.*;
 import away3d.core.scene.*;
 import away3d.core.material.*;
    import fr.seraf.wow.primitive.WOWPlane;
    import fr.seraf.wow.primitive.WSphere;
    import fr.seraf.wow.core.WOWEngine;
    import fr.seraf.wow.core.data.WVector;
    import fr.seraf.wow.constraint.WSpringConstraint;
 public class HelloWorld extends Sprite {
  private var wow:WOWEngine;
  private var sphere01:WSphere;
  private var sphere02:WSphere;
  private var sphere03:WSphere;
  var constraint:WSpringConstraint;
  var constraintb:WSpringConstraint;
  var view:View3D;
  var sphereA:Sphere;
  var sphereB:Sphere;
  var sphereC:Sphere;
  function HelloWorld() {
   stage.frameRate=60;
   addEventListener(Event.ENTER_FRAME,away3dloop);
   away3dcreate();
  }
  function away3dcreate():void {
   addChild(view=new View3D({x:stage.stageWidth / 2,y:stage.stageHeight /
2}));
   sphereA=new Sphere({material:new WireColorMaterial  });
   sphereB=new Sphere({material:new WireColorMaterial  });
   sphereC=new Sphere({material:new WireColorMaterial  });
   view.scene.addChild(sphereA);
   view.scene.addChild(sphereB);
   view.scene.addChild(sphereC);
   ///////////////////////
   wow=new WOWEngine(.4);
   wow.collisionResponseMode=wow.SELECTIVE;
   wow.addMasslessForce(new WVector(0,-2,0));
   sphere01=new WSphere(0,100,0,5,false,0.005,0.1,0.01);
   wow.addParticle(sphere01);
   //this sphere is fixed
   sphere02=new WSphere(100,200,0,5,true);
   wow.addParticle(sphere02);
   //add one constraint between the spheres
   constraint=new WSpringConstraint(sphere01,sphere02,.7);
   wow.addConstraint(constraint);

   sphere03=new WSphere(100,400,0,5,true);
   wow.addParticle(sphere03);
   //add one constraint between the spheres
   constraintb=new WSpringConstraint(sphere01,sphere03,.7);
   wow.addConstraint(constraintb);
   //
   //we create a plane just for fun
   var planeFixed:WOWPlane=new WOWPlane  ;
   planeFixed.setPosition(0,300,0);
   planeFixed.setRotation(0,3,30);
   planeFixed.elasticity=0.5;
   planeFixed.friction=0.0;
   wow.addParticle(planeFixed);
  }
  function away3dloop(event:Event):void {
   wow.step();
   view.camera.moveTo(sphereA.position);
   view.camera.rotationY=mouseX / 2;
   view.camera.rotationX=mouseY / 2;
   view.camera.moveBackward(2500);

   //sphereA.rotationY+= 1;

   sphereA.x=sphere01.px;
   sphereA.y=sphere01.py;
   sphereA.z=sphere01.pz;
   sphereB.x=sphere02.px;
   sphereB.y=sphere02.py;
   sphereB.z=sphere02.pz;
   sphereC.x=sphere03.px;
   sphereC.y=sphere03.py;
   sphereC.z=sphere03.pz;
   //sphereB.moveTo(new Number3d(sphere02.px,sphere02.py,sphere02.pz));

   //trace("sphere01",sphere01.px,sphere01.py,sphere01.pz);
            //trace("sphere02",sphere02.px,sphere02.py,sphere02.pz);

   view.render();
  }
 }
} 